package com.borqs.samples;

import java.util.ArrayList;

import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.util.Log;

public abstract class BaseDBAnalysis {

    private final String TAG = "BaseDBDataAnalysis";

    private Context mContext = null;

    public BaseDBAnalysis(Context context) {
        mContext = context;
    }

    public abstract ArrayList<Object> getConclusiveData();

    public abstract ArrayList<Object> getSuspiciousData();

    /**
     * 
     * @param uri
     * @return
     */
    protected Cursor query(Uri uri) {
        Cursor c = null;
        c = mContext.getContentResolver().query(uri, null, null, null,
                "_id ASC");
        if (c != null && c.moveToFirst()) {
            return c;
        } else {
            Log.i(TAG, "query failure!");
        }
        return null;
    }

    /**
     * 
     * @param uri
     * @param projection
     * @param whereRow
     * @param where
     * @return
     */
    protected Cursor query(Uri uri, String[] projection, String whereRow,
            int where) {
        Cursor c = null;
        c = mContext.getContentResolver().query(uri, projection,
                whereRow + "=?", new String[] { where + "" }, "_id ASC");

        if (c != null && c.moveToFirst()) {
            return c;
        } else {
            Log.i(TAG, "query failure!");
        }
        return null;
    }
}
